import React from 'react';

export class App extends React.Component {
  constructor() {
    super();
    this.state = {
      txt: 'xxx',
    };
  }

  // input 事件处理函数
  inputHandler = (e) => {
    console.log(e.target.value);
    // 设置页面状态
    this.setState({
      txt: e.target.value,
    });
  };

  render() {
    return (
      <div>
        <h1>{this.state.txt}</h1>
        <input
          type={'text'}
          value={this.state.txt}
          onChange={this.inputHandler}
        />
      </div>
    );
  }
}

export default App;
